!function () {
    var apis = {}

    /**
     * 用户相关Api
     */
    $.extend(apis, {
        /**
         * 统计
         */
        analyses_dashboard: {
            url: '/api/admin/v1/analyses/dashboard'
        },
        analyses_orders_data: {
            url: '/api/admin/v1/analyses/orders_data'
        },
        analyses_users_data: {
            url: '/api/admin/v1/analyses/users_data'
        },
        analyses_withdraws_data: {
            url: '/api/admin/v1/analyses/withdraws_data'
        },
        /**
         * 订单
         */
        orders_analyse: {
            url: '/api/admin/v1/orders/analyse'
        },
        orders_browse: {
            url: '/api/admin/v1/orders/browse'
        },
        user_orders_analyse: {
            url: '/api/admin/v1/user_orders/analyse'
        },
        user_orders_browse: {
            url: '/api/admin/v1/user_orders/browse'
        },
        /**
         * 维权订单
         */
        refunds_analyse: {
            url: '/api/admin/v1/refunds/analyse'
        },
        refunds_browse: {
            url: '/api/admin/v1/refunds/browse'
        },
        /**
         * 用户
         */
        users_analyse: {
            url: '/api/admin/v1/users/analyse'
        },
        users_browse: {
            url: '/api/admin/v1/users/browse'
        },
        users_load: {
            url: '/api/admin/v1/users/load'
        },
        users_add: {
            url: '/api/admin/v1/users/add',
            method: 'POST'
        },
        users_edit: {
            url: '/api/admin/v1/users/edit',
            method: 'POST'
        },
        users_delete: {
            url: '/api/admin/v1/users/delete',
            method: 'POST'
        },
        users_validate: {
            url: '/api/admin/v1/users/validate',
            method: 'POST'
        },
        users_send_msg: {
            url: '/api/admin/v1/users/send_msg',
            method: 'POST'
        },
        users_edit_by_wechat: {
            url: '/api/admin/v1/users/edit_by_wechat',
            method: 'POST'
        },
        users_agency_change: {
            url: '/api/admin/v1/users/agency_change',
            method: 'POST'
        },
        users_agency_cancel: {
            url: '/api/admin/v1/users/agency_cancel',
            method: 'POST'
        },
        users_alimama_adzones: {
            url: '/api/admin/v1/users/alimama_adzones'
        },
        users_alimama_adzone_create: {
            url: '/api/admin/v1/users/alimama_adzone_create',
            method: 'POST'
        },
        users_image_browse: {
            url: '/api/admin/v1/users/image_browse'
        },
        users_image_add: {
            url: '/api/admin/v1/users/image_add',
            method: 'POST'
        },
        users_image_edit: {
            url: '/api/admin/v1/users/image_edit',
            method: 'POST'
        },

        /**
         * 账号
         */
        accounts_analyse: {
            url: '/api/admin/v1/accounts/analyse'
        },
        accounts_browse: {
            url: '/api/admin/v1/accounts/browse'
        },
        accounts_load: {
            url: '/api/admin/v1/accounts/load'
        },
        accounts_add: {
            url: '/api/admin/v1/accounts/add',
            method: 'POST'
        },
        accounts_edit: {
            url: '/api/admin/v1/accounts/edit',
            method: 'POST'
        },
        accounts_delete: {
            url: '/api/admin/v1/accounts/delete',
            method: 'POST'
        },

        /**
         * 用户搜索
         */
        searchs_browse: {
            url: '/api/admin/v1/searchs/browse'
        },
        /**
         * 用户浏览
         */
        views_browse: {
            url: '/api/admin/v1/views/browse'
        },
        /**
         * 用户文本
         */
        texts_browse: {
            url: '/api/admin/v1/texts/browse'
        }
    });

    /**
     * 商品相关Api
     */
    $.extend(apis, {
        /**
         * 商品类别
         */
        categories_tree: {
            url: '/api/admin/v1/categories/tree'
        },
        /**
         * 商品
         */
        goodses_browse: {
            url: '/api/admin/v1/goodses/browse'
        },
        goodses_load: {
            url: '/api/admin/v1/goodses/load'
        },
        goodses_add: {
            url: '/api/admin/v1/goodses/add',
            method: 'POST'
        },
        goodses_edit: {
            url: '/api/admin/v1/goodses/edit',
            method: 'POST'
        },
        goodses_delete: {
            url: '/api/admin/v1/goodses/delete',
            method: 'POST'
        }
    });

    /**
     * 财务相关Api
     */
    $.extend(apis, {
        /**
         * 财务
         */
        finances_analyse: {
            url: '/api/admin/v1/finances/analyse'
        },
        finances_browse: {
            url: '/api/admin/v1/finances/browse'
        },
        /**
         * 提现
         */
        withdraws_analyse: {
            url: '/api/admin/v1/withdraws/analyse'
        },
        withdraws_browse: {
            url: '/api/admin/v1/withdraws/browse'
        },
        withdraws_load: {
            url: '/api/admin/v1/withdraws/load'
        },
        withdraws_status: {
            url: '/api/admin/v1/withdraws/status',
            method: 'POST'
        },
        withdraws_edit_note: {
            url: '/api/admin/v1/withdraws/edit_note',
            method: 'POST'
        }
    });

    /**
     * 建议反馈Api
     */
    $.extend(apis, {
        /**
         * 建议反馈
         */
        suggestions_browse: {
            url: '/api/admin/v1/suggestions/browse'
        },
        suggestions_load: {
            url: '/api/admin/v1/suggestions/load'
        },
        suggestions_add: {
            url: '/api/admin/v1/suggestions/add',
            method: 'POST'
        },
        suggestions_edit: {
            url: '/api/admin/v1/suggestions/edit',
            method: 'POST'
        },
        suggestions_delete: {
            url: '/api/admin/v1/suggestions/delete',
            method: 'POST'
        },
        /**
         * 自动回复
         */
        responses_browse: {
            url: '/api/admin/v1/responses/browse'
        },
        responses_load: {
            url: '/api/admin/v1/responses/load'
        },
        responses_add: {
            url: '/api/admin/v1/responses/add',
            method: 'POST'
        },
        responses_edit: {
            url: '/api/admin/v1/responses/edit',
            method: 'POST'
        },
        responses_delete: {
            url: '/api/admin/v1/responses/delete',
            method: 'POST'
        }
    });

    /**
     * 文章相关Api
     */
    $.extend(apis, {
        /**
         * 文章
         */
        articles_analyse: {
            url: '/api/admin/v1/articles/analyse'
        },
        articles_browse: {
            url: '/api/admin/v1/articles/browse'
        },
        articles_load: {
            url: '/api/admin/v1/articles/load'
        },
        articles_add: {
            url: '/api/admin/v1/articles/add',
            method: 'POST'
        },
        articles_edit: {
            url: '/api/admin/v1/articles/edit',
            method: 'POST'
        },
        articles_delete: {
            url: '/api/admin/v1/articles/delete',
            method: 'POST'
        },
        articles_image_browse: {
            url: '/api/admin/v1/articles/image_browse'
        },
        articles_image_add: {
            url: '/api/admin/v1/articles/image_add',
            method: 'POST'
        },
        articles_image_edit: {
            url: '/api/admin/v1/articles/image_edit',
            method: 'POST'
        }
    });

    /**
     * 权限相关Api
     */
    $.extend(apis, {
        /**
         * 权限
         */
        permissions_find: {
            url: '/api/admin/v1/permissions/find'
        },
        permissions_save: {
            url: '/api/admin/v1/permissions/save',
            method: 'POST',
            contentType: 'application/json'
        }
    });

    /**
     * 基础设置Api
     */
    $.extend(apis, {
        /**
         * 字典
         */
        dicts_browse: {
            url: '/api/admin/v1/dicts/browse'
        },
        dicts_add: {
            url: '/api/admin/v1/dicts/add',
            method: 'POST'
        },
        dicts_edit: {
            url: '/api/admin/v1/dicts/edit',
            method: 'POST'
        },
        dicts_delete: {
            url: '/api/admin/v1/dicts/delete',
            method: 'POST'
        },
        dicts_sort: {
            url: '/api/admin/v1/dicts/sort',
            method: 'POST',
            contentType: 'application/json'
        },
        /**
         * 设置
         */
        settings_load: {
            url: '/api/admin/v1/settings/load'
        },
        settings_save: {
            url: '/api/admin/v1/settings/save',
            method: 'POST'
        },
        settings_wechat_update: {
            url: '/api/admin/v1/settings/wechat_update',
            method: 'POST'
        },
        reindex_goodses_search: {
            url: '/api/admin/v1/settings/reindex_goodses_search'
        },
        recapture_user_data: {
            url: '/api/admin/v1/settings/recapture_user_data'
        },
        update_wechat_tags: {
            url: '/api/admin/v1/settings/update_wechat_tags'
        }
    });

    window.adminApi = function (apiName, apiData) {
        var apiInfo = $.extend(true, {}, apis[apiName]);
        if (!apiInfo.dataType) {
            apiInfo.dataType = 'json';
        }
        if (apiData) {
            apiInfo.data = apiData;
        }
        apiInfo.url = HOST + apiInfo.url;
        return $.ajax(apiInfo).then(function (data) {
            return data;
        }, function (err) {
            utils.requestError(err);
        });
    }
}();